package util;

import java.util.Arrays;

/**
 * Created by Gerardo on 1/21/14.
 */
public class Password {
	private transient char[] password;

	public static Password of(char[] password) {
		return new Password(password);
	}

	private Password(char[] password) {
		this.password = password;
	}

	private void clear() {
		Arrays.fill(password, ' ');
	}

	//TODO pasar a una clase abstracta
	public String flush() {
		final String s = new String(password);
		clear();
		return s;
	}

	@Override
	public String toString() {
		return "*********";
	}

	@Override
	protected void finalize() throws Throwable {
		clear();
	}

	public abstract class Secure
	{
		private final Password password;

		protected Secure(final Password password) {
			this.password = password;
		}

		public void start() {
			execute(password.flush());
			password.clear();
		}

		public abstract void execute(String password);

	}

}
